﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows;
using WPFDiagramming.Interfaces;

namespace WPFDiagramming.Designer
{
    public class EntityDesigner : IDesigner
    {
        public double Height { get; set; }
        public double Width { get; set; }

        private double RadiusX
        {
            get
            {
                return Width * 0.07;
            }
        }
        private double RadiusY
        {
            get
            {
                return Width * 0.07;
            }
        }

        public EntityDesigner(double width, double height)
        {
            this.Width = width;
            this.Height = height;
        }

        public Geometry Draw()
        {
            List<PathFigure> figures = new List<PathFigure>();

            PathFigure pathFigure = new PathFigure();

            pathFigure.StartPoint = new Point(0, RadiusY);
            pathFigure.Segments.Add(new ArcSegment(new Point(RadiusX, 0), new Size(RadiusX * 2, RadiusY * 2), 0, false, SweepDirection.Clockwise, true));
            pathFigure.Segments.Add(new LineSegment(new Point(this.Width - RadiusX, 0), true));
            pathFigure.Segments.Add(new ArcSegment(new Point(this.Width, RadiusX), new Size(RadiusX * 2, RadiusY * 2), 0, false, SweepDirection.Clockwise, true));
            pathFigure.Segments.Add(new LineSegment(new Point(this.Width, this.Height - RadiusY), true));
            pathFigure.Segments.Add(new ArcSegment(new Point(this.Width - RadiusX, this.Height), new Size(RadiusX * 2, RadiusY * 2), 0, false, SweepDirection.Clockwise, true));
            pathFigure.Segments.Add(new LineSegment(new Point(RadiusX, this.Height), true));
            pathFigure.Segments.Add(new ArcSegment(new Point(0, this.Height - RadiusY), new Size(RadiusX * 2, RadiusY * 2), 0, false, SweepDirection.Clockwise, true));

            pathFigure.IsClosed = true;

            figures.Add(pathFigure);

            return new PathGeometry(figures, FillRule.EvenOdd, null);
        }

    }
}
